package com.ftwj.demo.config.solr;

import java.io.Serializable;
import java.util.List;

public class PageInfoBean implements Serializable {

	/** serialVersionUID*/ 
	private static final long serialVersionUID = 1L;
	
	//当前页，默认：1
	private Integer curPage=1;
	//每页条数，默认：10
	private Integer perPage=10;
	//页面总页数
	private Long totalPage;
	//数据总条数
	private Long totalNum;
	//起始行数
	private Integer startIndex;
	//结束行数
	private Long lastIndex;
	//是否存在前一页
	private Boolean hasPreviousPage = false;
	//是否存在后一页
	private Boolean hasNextPage = false;
	//结果集存放List
	private List<? extends Object> recList;
	
	public PageInfoBean() {
	}
	public PageInfoBean(Integer curPage, Integer perPage) {
		super();
		this.curPage = curPage;
		this.perPage = perPage;
	}
	
	public Integer getCurPage() {
		return curPage;
	}
	public PageInfoBean setCurPage(Integer curPage) {
		this.curPage = curPage;
		return this;
	}
	public Integer getPerPage() {
		return perPage;
	}
	public PageInfoBean setPerPage(Integer perPage) {
		this.perPage = perPage;
		return this;
	}
	
	public Long getTotalPage() {
		return totalPage;
	}
	public Long getTotalNum() {
		return totalNum;
	}
	public void setTotalNum(Long totalNum) {
		this.totalNum = totalNum;
	}
	
	public Integer getStartIndex() {
		return startIndex;
	}
	public Long getLastIndex() {
		return lastIndex;
	}
	public Boolean getHasPreviousPage() {
		return hasPreviousPage;
	}
	public Boolean getHasNextPage() {
		return hasNextPage;
	}
	
	public List<?> getRecList() {
		return recList;
	}
	public void setRecList(List<?> recList) {
		this.recList = recList;
	}
	
	/**
	 *	计算开始索引
	 */
	public void calStartIndex() {
		this.startIndex = (curPage - 1) * perPage;
	}
	
	/**
	 *	计算结束索引
	 */
	public void calLastIndex() {
	   if (totalNum < perPage) {
		   this.lastIndex = totalNum;
	   }else if((totalNum % perPage == 0) || (totalNum % perPage != 0 && curPage < totalPage)){
		   this.lastIndex = curPage * perPage * 1L;
       } else if(totalNum % perPage != 0 && curPage * 1L == totalPage){
           this.lastIndex = totalNum;
	   } 
	}
	
	/**
	 *	计算总页数
	 */
	public void calTotalPages() {
	   if(totalNum % perPage == 0){
		   this.totalPage = totalNum / perPage;
	   }else{
		   this.totalPage= (totalNum / perPage) + 1;
	   }
	}
	
	/**
	 *	判断首尾页
	 */
	public void judgePage() {
		if(curPage>1) {
			hasPreviousPage=true;
		}
		if(curPage<totalPage) {
			hasPreviousPage=true;
		}
	}

	public void calPageParam(){
		calTotalPages();
		calStartIndex();
		calLastIndex();
		judgePage();
	}
	
	@Override
	public String toString() {
		return "PageInfoBean [curPage=" + curPage + ", perPage=" + perPage + ", totalPage=" + totalPage + ", totalNum="
				+ totalNum + ", startIndex=" + startIndex + ", lastIndex=" + lastIndex + ", hasPreviousPage="
				+ hasPreviousPage + ", hasNextPage=" + hasNextPage + ", recList=" + recList + "]";
	}
	
}
